package lzyc.pointsManagement.business.approval.convertor;

import lzyc.pointsManagement.business.approval.domain.ApprovalInfo;
import lzyc.pointsManagement.business.approval.dto.ApprovalInfoDto;
import lzyc.pointsManagement.business.config.ApprovalStatus;
import lzyc.pointsManagement.business.config.BizType;
import lzyc.pointsManagement.common.utils.StringUtils;
import lzyc.pointsManagement.common.utils.uuid.IdUtils;

public class ApprovalInfoConvertor {
    public static ApprovalInfoDto convertToDto(ApprovalInfo approvalInfo) {
        ApprovalInfoDto approvalInfoDto = new ApprovalInfoDto();
        approvalInfoDto.setApprovalId(approvalInfo.getApprovalId());
        approvalInfoDto.setProjectId(approvalInfo.getProjectId());
        approvalInfoDto.setStatus(ApprovalStatus.fromCode(approvalInfo.getStatus()));
        approvalInfoDto.setType(approvalInfo.getType());
        approvalInfoDto.setApplyUserId(approvalInfo.getApplyUserId());
        return approvalInfoDto;
    }

    public static ApprovalInfo convertToEntity(ApprovalInfoDto approvalInfoDto) {
        ApprovalInfo approvalInfo = new ApprovalInfo();
        if (StringUtils.isEmpty(approvalInfoDto.getApprovalId())) {
            approvalInfo.setApprovalId(IdUtils.randomUUID());
        } else {
            approvalInfo.setApprovalId(approvalInfoDto.getApprovalId());
        }
        approvalInfo.setProjectId(approvalInfoDto.getProjectId());
        approvalInfo.setStatus(approvalInfoDto.getStatus().getCode());
        approvalInfo.setType(approvalInfoDto.getType());
        approvalInfo.setApplyUserId(approvalInfoDto.getApplyUserId());
        return approvalInfo;
    }
}
